import java.util.Stack;

public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minstack;

    public MinStack() {
        stack=new Stack<Integer>();
        minstack=new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()){
            minstack.push(val);
        }else if(val<=minstack.peek()){
            minstack.push(val);
        }
    }

    public void pop() {
        if(!stack.empty()) {
            int val = stack.pop();
            if (val == minstack.peek()) {
                minstack.pop();
            }
        }else{
            return ;
        }
    }

    public int top() {
        if (stack.empty()){
            return -1;
        }
        return stack.peek();

    }

    public int getMin() {
        if (minstack.empty()){
            return -1;
        }
        return minstack.peek();

    }
}
